import config from 'config'
import httpFetch from 'share/httpFetch'
const url = `${config.baseUrl}/ledger`;
function urlJoin(params) {
  let res = [];
  for(let key in params){
    res.push(`${key}=${params[key]}`)
  }
  return res.join('&');
}

export default {

  //凭证模版定义--固化字段列表
  getJournalList(type,setOfBooksId){
    return httpFetch.get(`${url}/api/journal/line/define/query/curing/field?type=${type}&setOfBooksId=${setOfBooksId}`);
  },

  //凭证模版定义--凭证明细编码列表
  getCodeList(type,setOfBooksId){
    return httpFetch.get(`${url}/api/journal/line/define/query/custom/field/${type}?setOfBooksId=${setOfBooksId}`);
  },

  //凭证模版定义--获取列表
  getTemplateList(setOfBooksId,params){
    return httpFetch.get(`${url}/api/journal/line/define/query/by/page?setOfBooksId=${setOfBooksId}`,params);
  },

  //凭证模版定义--新增
  addTemplate(params,userOID){
    return httpFetch.post(`${url}/api/journal/line/define?operatorOid=${userOID}`,params);
  },

  //凭证模版定义--更新
  updateTemplate(params,userOID){
    return httpFetch.put(`${url}/api/journal/line/define?operatorOid=${userOID}`,params);
  },

  //凭证校验规则定义--获取列表
  getValidateList(params){
    return httpFetch.get(`${url}/api/journal/rule/detail/query/by/page?${urlJoin(params)}`)
  },

  //凭证模版定义--新增
  addValidate(params,userOID){
    return httpFetch.post(`${url}/api/journal/rule/detail?operatorOid=${userOID}`,params);
  },

  //凭证模版定义--更新
  updateValidate(params,userOID){
    return httpFetch.put(`${url}/api/journal/rule/detail?operatorOid=${userOID}`,params);
  },

  //凭证模版定义--获取规则名称列表
  getRuleNameList(){
    return httpFetch.get(`${url}/api/journal/rule/query/list`);
  },

  //凭证模版定义--获取下方躺框的列表
  getAllList(setOfBooksId){
    return httpFetch.get(`${url}/api/journal/line/define/query/list?lineType=1002&setOfBooksId=${setOfBooksId}`)
  },

  getValidateDetail(id){
    return httpFetch.get(`${url}/api/journal/rule/detail?id=${id}`)
  },

  getRuleList(params){
    return httpFetch.get(`${url}/api/rule/define/select/list?${urlJoin(params)}`)
  },

  // 删除
  deleteJournal(id){
    return httpFetch.delete(`${url}/api/journal/line/define/delete/by/id?id=${id}`)
  },

  // 删除校验
  validateDelete(id){
    return httpFetch.get(`${url}/api/journal/line/define/check/before/deleted?id=${id}`)
  },

  // 删除模版校验
  deleteValidateRule(id){
    return httpFetch.delete(`${url}/api/journal/rule/detail?id=${id}`)
  }
};
